﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using FXnaInfrastructure;


namespace GWPresentation
{
    /// <summary>
    /// 配置文件管理服务，提供应用程序配置文件的所有基础操作
    /// </summary>
    public class ConfigService
    {
        protected ConfigService()
        {

            this._settingInfo = new SettingInfo();

        }




        static ConfigService currentService;

        public static ConfigService CurrentService
        {
            get
            {

                if (currentService == null)
                {
                    currentService = new ConfigService();

                }

                return ConfigService.currentService;

            }

        }


        SettingInfo _settingInfo;

        /// <summary>
        /// 程序配置信息
        /// </summary>
        public SettingInfo SettingInfo
        {
            get { return _settingInfo; }
            set { _settingInfo = value; }
        }

        string _fileName = "fApp.set";

        /// <summary>
        /// 从硬盘加载配置文件
        /// </summary>
        public void LoadConfig()
        {
            string filePath = ApplicationService.CurrentService.GetApplicationPath(ApplicationPath.APPPATH) + this._fileName;

            bool b = false;

            if (System.IO.File.Exists(filePath))
            {
                this._settingInfo = FileHelper.OpenFromBinary(filePath) as SettingInfo;
                if (this._settingInfo == null)
                {
                    this._settingInfo = new SettingInfo();

                }



            }
            else
            {
                this._settingInfo = new SettingInfo();

            }


        }


        /// <summary>
        /// 将配置文件保存会硬盘
        /// </summary>
        public void SaveConfig()
        {

            string filePath = ApplicationService.CurrentService.GetApplicationPath(ApplicationPath.APPPATH) + this._fileName;

            FileHelper.SaveToBinary(filePath, this._settingInfo);


        }

    }
}
